package com.slowfly.rule.engine.controller;

import com.slowfly.rule.engine.component.SnowFlakeComponent;
import com.slowfly.rule.engine.config.RiskConfig;
import com.slowfly.rule.engine.param.*;
import com.slowfly.rule.engine.result.*;
import com.slowfly.rule.engine.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 风控引擎
 */
@Slf4j
@RestController("/rule/engine/admin")
public class RuleEngineAdminController {

    @Autowired
    private RiskConfig riskConfig;
    @Autowired
    private ISceneService sceneService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IRuleService ruleService;
    @Autowired
    private IDecisionService decisionService;
    @Autowired
    private IRecordService recordService;
    @Autowired
    private IStrategyRecordService strategyRecordService;
    @Autowired
    private SnowFlakeComponent snowFlakeComponent;
    @Autowired
    private IFeatureService featureService;

    @RequestMapping("config/get")
    public ConfigResult getConfig() {
        ConfigResult configResult = new ConfigResult();
        BeanUtils.copyProperties(riskConfig, configResult);
        return configResult;
    }

    public List<SceneResult> listScene() {
        return sceneService.listScene();
    }

    public PageResult<SceneResult> pageScene(SceneParam param) {
        return sceneService.pageScene(param);
    }

    public boolean addScene(SceneParam param) {
        return sceneService.addScene(param);
    }

    public boolean editScene(SceneParam param) {
        return sceneService.editScene(param);
    }

    public boolean deleteScene(SceneParam param) {
        return sceneService.deleteScene(param);
    }

    public List<StrategyResult> listStrategy() {
        return strategyService.listStrategy();
    }

    public List<StrategyResult> listStrategyByParam(StrategyParam param) {
        return strategyService.listStrategyByParam(param);
    }

    public PageResult<StrategyResult> pageStrategy(StrategyParam param) {
        return strategyService.pageStrategy(param);
    }

    public boolean addStrategy(StrategyParam param) {
        return strategyService.addStrategy(param);
    }

    public boolean editStrategy(StrategyParam param) {
        return strategyService.editStrategy(param);
    }

    public boolean deleteStrategy(StrategyParam param) {
        return strategyService.deleteStrategy(param);
    }

    public List<RuleResult> listRule() {
        return ruleService.listRule();
    }

    public PageResult<RuleResult> pageRule(RuleParam param) {
        return ruleService.pageRule(param);
    }

    public boolean addRule(RuleParam param) {
        return ruleService.addRule(param);
    }

    public boolean editRule(RuleParam param) {
        return ruleService.editRule(param);
    }

    public boolean deleteRule(RuleParam param) {
        return ruleService.deleteRule(param);
    }

    public List<DecisionResult> listDecision() {
        return decisionService.listDecision();
    }

    public PageResult<DecisionResult> pageDecision(DecisionParam param) {
        return decisionService.pageDecision(param);
    }

    public boolean addDecision(DecisionParam param) {
        return decisionService.addDecision(param);
    }

    public boolean editDecision(DecisionParam param) {
        decisionService.editDecision(param);
        return true;
    }

    public boolean deleteDecision(DecisionParam param) {
        return decisionService.deleteDecision(param);
    }

    public PageResult<RecordResult> pageRecord(RecordParam param) {
        return recordService.pageRecord(param);
    }

    public PageResult<StrategyRecordResult> pageStrategyRecord(StrategyRecordParam param) {
        return strategyRecordService.pageStrategyRecord(param);
    }

    public boolean checkDeleteFeature(Integer featureId) {
        return ruleService.checkDeleteFeature(featureId) && decisionService.checkDeleteFeature(featureId);
    }
}
